package org.x.usermod.controller;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.x.commonmod.config.Result;
import org.x.usermod.dto.SysMenuCreateDTO;
import org.x.usermod.dto.SysMenuListDTO;
import org.x.usermod.dto.SysMenuUpdateDTO;
import org.x.usermod.entity.SysMenu;
import org.x.usermod.service.ISysMenuService;
import org.springframework.web.bind.annotation.RestController;


/**
 * 菜单表 控制层。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@RestController
@RequestMapping("/api/sysMenu")
public class SysMenuController {

    @Autowired
    private ISysMenuService sysMenuService;

    /**
     * 添加 菜单表
     *
     * @param sysMenuCreateDTO 菜单表
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("/create")
    public Result create(@RequestBody SysMenuCreateDTO sysMenuCreateDTO) {
        return Result.ok(sysMenuService.create(sysMenuCreateDTO));
    }


    /**
     * 根据主键逻辑删除菜单表
     *
     * @param id 主键
     */
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Integer id) {
       return Result.ok( sysMenuService.removeById(id));
    }

    /**
     * 根据主键更新菜单表
     *
     * @param sysMenuUpdateDTO 菜单表
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("/update")
    public Result update(@RequestBody SysMenuUpdateDTO sysMenuUpdateDTO) {
        return Result.ok( sysMenuService.update(sysMenuUpdateDTO));
    }


    /**
     * 分页查询所有菜单表
     *
     * @return 所有数据
     */
    @GetMapping("/list")
    public Result list(SysMenuListDTO sysMenuListDTO){
        return Result.ok(sysMenuService.pageList(sysMenuListDTO));
    }

}